#include "CApp.h"

CApp::CApp() {
  WNDCLASS wc;

  ZeroMemory(&wc, sizeof(WNDCLASS));
  wc.style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc   = m_proc.Dispatch;
  wc.cbClsExtra    = 0;
  wc.cbWndExtra    = 0;
  wc.hInstance     = GetModuleHandle(NULL);
  wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
  wc.lpszMenuName  = NULL;
  wc.lpszClassName = "WINDOW";

  ::RegisterClass(&wc);
}

CApp::~CApp() {
  ::UnregisterClass("WINDOW", GetModuleHandle(NULL));
}

void CApp::OnInit() {
}

void CApp::OnExit() {
}

int CApp::Exec() {
  MSG msg;

  this->OnInit();
  while (GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  this->OnExit();

  return msg.wParam;
}

